﻿@model Telecom.Data.LAP_THIETBI

<div class="easyui-layout" id="Layout_dm_dau_noi_thiet_bi">
    <div id="pannel_thiet_bi_dau_noi" data-options="region:'west', collapsible:false" title="Đối tượng" style="width: 310px; padding: 10px">
        
        <p style="padding:3px 0"><input class="easyui-combobox" style="width:280px; height:27px" id="donvi_daunoi_tb" name="donvi_daunoi_tb"></p>
        <p style="padding:3px 0"><input class="easyui-combobox" style="width:280px; height:27px" id="touanly_daunoi_tb" name="touanly_daunoi_tb"></p>
        <p style="padding:3px 0"><input class="easyui-combogrid" style="width:280px; height:27px" id="vnpt_site_daunoi_tb" name="vnpt_site_daunoi_tb"></p>

        <div class="eareas_display_thiet_bi">

        </div>

    </div>
    <div id="pannel_cai_dat_dau_noi" data-options="region:'center'" style="padding:5px; position:relative" title="Cài đặt đấu nối thiết bị">
        

        <div id="eareas_cau_hinh_dau_noi_thiet_bi">

        </div>

    </div>
</div>

<script type="text/javascript">

    $(document).ready(function () {

        var donvi_daunoi_select = "";

        $("#Layout_dm_dau_noi_thiet_bi").css('width', $(window).width() - 5);
        $("#Layout_dm_dau_noi_thiet_bi").height($(window).height() - 100);

        

        $("#eareas_cau_hinh_dau_noi_thiet_bi").width($("#pannel_cai_dat_dau_noi").width() - 315);
        $("#eareas_cau_hinh_dau_noi_thiet_bi").height($(window).height() - 180);


        $("#donvi_daunoi_tb").combobox({
            url: _nameSubDomain + "/Donvi_ToQL/Get_DonVi_To_OnJson_InsertText",
            valueField: "id",
            textField: "text",
            onSelect: function (row) {

                donvi_daunoi_select = row.id;
                $("#touanly_daunoi_tb").combobox({ url: _nameSubDomain + "/Donvi_ToQL/Get_ToAL_To_OnJson_InsertText?ma=" + row.id });
            }
        });

        $("#touanly_daunoi_tb").combobox({
            valueField: "MA",
            textField: "TEN",
            onSelect: function (row) {

                $("#vnpt_site_daunoi_tb").combogrid({ url: _nameSubDomain + "/DaunoiTB/List_VNPT_DAU_NOI?donviQl=" + donvi_daunoi_select + "&ToQL=" + row.MA + "&TramVT=PON" })

            },
        });

        $("#vnpt_site_daunoi_tb").combogrid({

            panelWidth: 275,
            idField: 'SITEID',
            textField: 'TEN',
            fitcomlumm: true,
            columns: [[
                //{ field: 'MA', title: 'Mã TB', width: 90 },
                { field: 'TEN', title: 'Tên SITE', width: 110 },
                {
                    field: 'DIACHI', title: 'ĐC SITE', width: 160
                },
            ]],
            onSelect: function (index, row) {
                
                LoadTBGPON();
                

            }
        });

        

        //$('#eareas_cau_hinh_dau_noi_thiet_bi').droppable({
        //    onDragEnter: function (e, source) {
        //        $(source).draggable('options').cursor = 'auto';
        //    },
        //    onDragLeave: function (e, source) {
        //        $(source).draggable('options').cursor = 'not-allowed';
        //    },
        //    onDrop: function (e, source) {
        //        var img = $(source).find('img').html();
        //        $(this).append(img)
        //        $(this).removeClass('over');
        //    }
        //});

    });

    function LoadTBGPON() {

        $(".eareas_display_thiet_bi").html("");

        $.ajax({ url: _nameSubDomain + "/Dm_ThietBi/ListThietByLoai?MaLoai=PON", async: false }).done(function (data) {

            var _Jsonoutput = JSON.parse(data);
            var html_tb = ""

            var checkIN = 1;
            for (var k = 0; k < _Jsonoutput.length; k++) {

                html_tb += "<div class='drag imagesObjectDarg'><img src=" + _nameSubDomain + "/Content/fileUpload/" + _Jsonoutput[k].HINHANH + " /><p class='nameObjectDarg'>" + _Jsonoutput[k].TEN + "</p></div>";
                checkIN++;

                

            }

            $(".eareas_display_thiet_bi").html(html_tb);

            



        });

        
        //$('.imagesObjectDarg').draggable({
        //    proxy: 'clone',
        //    revert: true,
        //    cursor: 'auto',
        //    onStartDrag: function () {
        //        $(this).draggable('options').cursor = 'not-allowed';
        //        $(this).draggable('proxy').css('z-index', 99999);
        //    },
        //    onStopDrag: function () {
        //        $(this).draggable('options').cursor = 'auto';
        //    }
        //});


    }

</script>